<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Station extends Model
{
    protected $table = 'mckj_mcstation';

    protected $fillable = ['name', 'addTime', 'address', 'longitude', 'latitude', 'coverPath'];

    const CREATED_AT = 'addTime';

    const UPDATED_AT = null;

    protected $dateFormat = 'U';

    const STATUS_OPEN = 0;
    const STATUS_CLOSED = 1;

    private static $statusText = [
        self::STATUS_OPEN => '正常',
        self::STATUS_CLOSED => '关闭',
    ];

    public function carbarns()
    {
        return $this->hasMany(Carbarn::class, "mcstationId");
    }

    public function orders()
    {
        return $this->hasMany(Order::class, "mcstationId");
    }

    public function getStatusTextAttribute()
    {
        return self::$statusText[$this->status] ?? "";
    }

    public function isOpen()
    {
        return $this->status == self::STATUS_OPEN;
    }
}
